﻿using DFGK.IService;
using DFGK.Service;
using DFGK_WMS.Common;
using DFGK_WMS.Model.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace DFGK_WMS.WebAPI.Controllers.PC.基础数据
{
    /// <summary>
    /// erp仓库表
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "PC")]
    public class StockController : BaseController
    {
        private readonly IStockService _stockService;
        private readonly IOtherTypeService _otherTypeService;
        private readonly IDepartMentService _departMentService;
        
        public StockController(IWebHostEnvironment environment, IStockService stockService, IOtherTypeService otherTypeService, IDepartMentService departMentService) : base(environment)
        {
            _stockService = stockService;
            _otherTypeService = otherTypeService;
            _departMentService = departMentService;
        }
        /// <summary>
        /// 仓库表
        /// </summary>
        /// <param name="WarehouseCode"></param>
        /// <param name="POMode"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetStockCascade(string? WarehouseCode, string? SPGroupCode, string? stockName, string? POMode, int pageIndex=1, int pageSize=1000)
        {
            if (pageIndex <= 0 || pageSize <= 0)
            {
                return Ok(BaseResult.Result("400", "分页条件有误！"));
            }
            int totalCount;
           
         
            var list = _stockService.GetCascadeStockData(WarehouseCode, SPGroupCode,stockName, POMode, pageIndex, pageSize, out totalCount);

            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200", totalCount));
            }
            return Ok(BaseResult.Result(null, "查询失败！", "500", 0));
        }
        /// <summary>
        /// 显示其他出入库单据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShowOtherType()
        {

            return Ok(_otherTypeService.ShowOtherType());
        }
        /// <summary>
        /// 获取部门列表
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetAllDepartment(string? name, int pageIndex = 1, int pageSize = 10)
        {
            if (pageIndex <= 0 || pageSize <= 0)
            {
                BaseResult.Result("400", "分页条件有误！");
            }
            var list = _departMentService.GetAllDepartment(name, pageIndex, pageSize, out var totalCount);
            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200", totalCount));
            }
            return Ok(BaseResult.Result(null, "查询失败！", "500", 0));
        }


    }
}
